package hrm.serviceimple;

import hrm.dao.EducationDAO;
import hrm.daoimple.EducationDAOImple;
import hrm.dto.insa.EducationDTO;
import hrm.service.EducationService;

import java.util.ArrayList;
import java.util.List;

public class EducationServiceImple implements EducationService {
	
	private EducationDAO educationDAO;
	private static EducationServiceImple educationService;
	
	private EducationServiceImple(){
		educationDAO=new EducationDAOImple();
	}
	
	public static EducationServiceImple getInstance(){
		if (educationService==null) {
			educationService=new EducationServiceImple();
		}
		return educationService;
	}
	

	public void setEducationDAO(EducationDAO educationDAO) {
		this.educationDAO = educationDAO;
	}

	@Override
	public List<EducationDTO> getEducation(EducationDTO dto) {
		List<EducationDTO> list = new ArrayList<EducationDTO>();
		list = educationDAO.getEducation(dto);
		for(int i=0;i<list.size();i++){
			if(list.get(i).getEdustartdate()!=null){
				list.get(i).setEdustartdate(list.get(i).getEdustartdate().substring(0, 10));
			}
			if(list.get(i).getGraduationdate()!=null){
				list.get(i).setGraduationdate(list.get(i).getGraduationdate().substring(0, 10));
			}
		}
		return list;
	}

	@Override
	public int insertEducation(EducationDTO dto) {
		if(educationDAO.insertEducation(dto)){
			return 1;
		} else {
			return -1;			
		}
	}

	@Override
	public void updateEducation(EducationDTO dto) {
		educationDAO.updateEducation(dto);
	}
	
	@Override
	public void deleteEducation(EducationDTO dto) {
		educationDAO.deleteEducation(dto);
	}

	

}
